﻿@namespace BlazorComponent
@typeparam TInput
@typeparam TValue
@inherits ComponentPartBase<TInput>

<div class="@CssProvider.GetClass("switch")" style="@CssProvider.GetStyle("switch")">
    @RenderPart(typeof(BSelectableInput<,>), "checkbox", arg0Name: "Type")
    @RenderPart(typeof(BRippleableRipple<>))
    <div class="@CssProvider.GetClass("track")" style="@CssProvider.GetStyle("track")"></div>
    <div class="@CssProvider.GetClass("thumb")" style="@CssProvider.GetStyle("thumb")">
        @RenderPart(typeof(BSwitchProgress<,>))
    </div>

    @GenText("left", LeftText, LeftIcon)
    @GenText("right", RightText, RightIcon)
</div>

@code {

    private RenderFragment GenText(string name, string? text, string? icon) => __builder =>
    {
        RenderFragment? childContent = null;

        if (!string.IsNullOrEmpty(icon))
        {
            childContent = @<BIcon @attributes="@GetAttributes(typeof(BIcon))">@icon</BIcon>;
        }
        else if (!string.IsNullOrEmpty(text))
        {
            childContent = b => b.AddContent(0, text);
        }

        if (childContent is not null)
        {
            <span class="@CssProvider.GetClass(name)"
                  style="@CssProvider.GetStyle(name)">
                @childContent
            </span>
        }
    };

}
